package com.mrx.xfriendship.converter;

import com.mrx.xfriendship.model.dto.TagDTO;
import com.mrx.xfriendship.model.po.TagPO;
import com.mrx.xfriendship.service.IMinioService;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingConstants;
import org.mapstruct.Named;

import javax.annotation.Resource;

/**
 * @author Mr.X
 * @since 2023-01-15 08:06
 */
@Mapper(componentModel = MappingConstants.ComponentModel.SPRING)
public abstract class TagConverter implements IConverter<TagPO, TagDTO> {

    @Resource
    private IMinioService minioService;

    @Override
    @Mapping(target = "avatar", qualifiedByName = "toPreviewAvatar")
    public abstract TagDTO toDTO(TagPO tagPO);

    @Named("toPreviewAvatar")
    public String toPreviewAvatar(String fileName) {
        return minioService.preview(fileName);
    }

}
